import request from "@/utils/request";
import {order} from "mockjs/src/mock/random/helper";

/**
 * 获取所有店铺和店铺对应的订单数量
 * @param params
 * @returns {Promise | Promise<unknown>}
 */
export function getOrderAccountList(params = {}){
  return request({
    url: `/order/getOrderAccountList`,
    method: 'get',
    params,
    timeout: 60000 * 5, // 1分钟
  })
}

/**
 * 获取订单各个状态的数量
 * @param params
 * @returns {Promise | Promise<unknown>}
 */
export function getOrderListNum(params = {}){
  return request({
    url: `/order/getOrderListNum`,
    method: 'get',
    params
  })
}

/**
 * 获取订单的列表数据
 * @param params
 * @returns {Promise | Promise<unknown>}
 */
export function getOrderList(params = {}){
  return request({
    url: '/order/getOrderList',
    method: 'get',
    params,
  })
}

/**
 * 获取falabella的订单数据
 * @param params
 * @returns {Promise | Promise<unknown>}
 */
export function getFaOrderList(params = {}){
  return request({
    url: '/order/getFaOrderList',
    method: 'get',
    params,
  })
}

/**
 * 获取shopee的订单数据
 * @param params
 * @returns {Promise | Promise<unknown>}
 */
export function getSpOrderList(params = {}){
  return request({
    url: '/order/getSpOrderList',
    params,
  })
}

/**
 * 获取shein的订单数据
 * @param params
 * @returns {Promise | Promise<unknown>}
 */
export function getSiOrderList(params = {}){
  return request({
    url: '/order/getSiOrderList',
    params,
  })
}

/**
 * 获取aliexpress的订单数据
 * @param params
 * @returns {Promise | Promise<unknown>}
 */
export function getAliexpressOrderList(params = {}){
  return request({
    url: '/order/getAliexpressOrderList',
    params,
  })
}

/**
 * 获取Amazon的订单数据
 * @param params
 * @returns {Promise | Promise<unknown>}
 */
export function getAmazonOrderList(params = {}){
  return request({
    url: '/order/getAmazonOrderList',
    params,
  })
}


/**
 * 获取小包的订单数据
 * @param params
 * @returns {Promise | Promise<unknown>}
 */
export function getPacketOrderList(params = {}){
  return request({
    url: '/order/getPacketOrderList',
    params,
  })
}

/**
 * 获取小包的物流数量
 * @param params
 * @returns {Promise | Promise<unknown>}
 */
export function getPacketCarrierNums(params = {}){
  return request({
    url: '/order/getPacketCarrierNums',
    params,
  })
}

/**
 * 获取小包的物流数量
 * @param orderId
 * @param data
 * @returns {Promise | Promise<unknown>}
 */
export function cancelPacketOrder(orderId, data){
  return request({
    url: '/order/cancelPacketOrder/' + orderId,
    data: data,
    method: 'patch',
  })
}

/**
 * 获取小包的物流数量
 * @param orderId
 * @param data
 * @returns {Promise | Promise<unknown>}
 */
export function createShippingOrder(orderId, data){
  return request({
    url: '/order/createShippingOrder/' + orderId,
    data: data,
    method: 'post',
    throwCatch: true,
    timeout: 60000,
  })
}

/**
 * 获取TikTok的订单数据
 * @param params
 * @returns {Promise | Promise<unknown>}
 */
export function getTikTokOrderList(params = {}){
  return request({
    url: '/order/getTikTokOrderList',
    params,
  })
}

export function getOrder(orderId,params = {}){
  return request({
    url: `/order/getOrderInfo/${orderId}`,
    params,
    method: 'get',
  })
}

/**
 * 传快递单
 * @param data
 * @returns {Promise<unknown>}
 */
export function deliveryOrder(data){
  return request({
    url: '/order/deliveryOrder',
    method: 'post',
    data,
    handleError: true,
  })
}

/**
 * 使用库存
 * @param data
 * @returns {Promise<unknown>}
 */
export function stockOrder(data){
  return request({
    url: '/order/stockOrder',
    method: 'post',
    data,
    handleError: true,
  })
}


/**
 * 忽略订单
 * @param data
 * @returns {Promise<unknown>}
 */
export function ignoreOrder(data){
  return request({
    url: '/order/ignoreOrder',
    method: 'post',
    data,
    handleError: true,
  })
}

/**
 * 重新提醒订单
 * @param params
 * @returns {Promise | Promise<unknown>}
 */
export function forgetIgnore(params){
  return request({
    url: `/order/forgetIgnore`,
    method: 'put',
    params
  })
}

/**
 * 删除订单
 * @param orderId
 * @returns {Promise | Promise<unknown>}
 */
export function deleteStickerOrder(orderId){
  return request({
    url: `/order/deleteStickerOrder/${orderId}`,
    method: 'delete',
  })
}


/**
 * 修改快递单
 * @param data
 * @returns {Promise | Promise<unknown>}
 */
export function editDelivery(data){
  return request({
    url: `/order/editDelivery/${data.orderId}`,
    method: 'patch',
    data,
  })
}

/**
 * 获取所有的快递公司
 * @returns {Promise | Promise<unknown>}
 */
export function getExpressList(){
  return request({
    url: '/express/getExpressList',
  })
}

/**
 * 获取订单的聚合模块数据
 * @param params
 * @returns {Promise<unknown>}
 */
export function getOrderGoodsNum(params){
  return request({
    url: '/order/getOrderGoodsNum',
    params
  })
}


/**
 * 打印面单
 * @param data
 * @deprecated
 * @returns {Promise | Promise<unknown>}
 */
export function printShipping(data){
  return request({
    url:`/order/printShipping`,
    method: 'post',
    data,
    responseType: "blob", // 需要加上
    isNotJson: true,
    timeout: 60000 * 5, // 5分钟
    handleError: true,
  })
}

/**
 * 打印单个面单
 * @param orderId
 * @param params 新增参数
 * @returns {Promise | Promise<unknown>}
 */
export function printShippingV2(orderId,params = {}){
  return request({
    url:`/order/printShippingV2/${orderId}`,
    params,
    method: 'post',
    responseType: "blob", // 需要加上
    isNotJson: true,
    timeout: 60000 * 5, // 5分钟
    handleError: true,
    handleResponse: true,
  })
}

/**
 * 下载面单
 * @param data
 * @returns {Promise | Promise<unknown>}
 */
export function downLoadShipping(data){
  return request({
    url:`/order/downLoadShipping`,
    method: 'post',
    data,
    responseType: "blob", // 需要加上
    isNotJson: true,
    timeout: 60000 * 5, // 1分钟
    handleError: true,
  })
}

/**
 * 订单转为库存
 * @param data
 * @returns {Promise<unknown>}
 */
export function order2Stock(data){
  return request({
    url: `/order/toStock`,
    method: 'post',
    data,
    handleError: true,
  })
}

/**
 * 确认并打印新标签
 * @param data
 * @returns {Promise<unknown>}
 */
export function confirmAndPrintTheNewPDF(data){
  return request({
    url: `/order/downConfirmAndPrintTheNewPDF`,
    method: 'post',
    data,
    responseType: "blob", // 需要加上
    isNotJson: true,
    timeout: 60000 * 5, // 1分钟
    handleError: true,
  })
}

/**
 * 确认并打印新标签
 * @param data
 * @returns {Promise<unknown>}
 */
export function PrintTheNewPDF(data){
  return request({
    url: `/order/downConfirmAndPrintTheNewPDF`,
    method: 'post',
    data,
    responseType: "arraybuffer",
    isNotJson: true,
    timeout: 60000 * 5, // 1分钟
    handleError: true,
  })
}

/**
 * 取消提示
 * @param orderId
 * @returns {Promise | Promise<unknown>}
 */
export function knowOrderCancel(orderId){
  return request({
    url: `/order/knowOrderCancel/${orderId}`,
    method: 'patch'
  })
}


/**
 * 生成拣货单
 * @param data
 * @returns {Promise | Promise<unknown>}
 */
export function createPicking(data){
  return request({
    url: `/order/createPicking`,
    data,
    method: 'post',
    handleError: true,
  })
}

/**
 * 每个平台的订单数量
 * @param params
 * @returns {Promise | Promise<unknown>}
 */
export function getOrderPlatformNum(params = {}){
  return request({
    url: '/order/getOrderPlatformNum',
    params,
  })
}


/**
 * 添加包装服务
 * @param data
 * @returns {Promise<unknown>}
 */
export function addPackage(data){
  return request({
    url: '/order/addPackage',
    data,
    method: 'post',
    handleError: true,
  })
}

/**
 * 修改包装服务
 * @param data
 * @returns {Promise<unknown>}
 */
export function alterPackage(data){
  return request({
    url: '/order/alterPackage',
    data,
    method: 'post',
    handleError: true,
  })
}

/**
 * 移除包装服务
 * @param data
 * @returns {Promise<unknown>}
 */
export function removePackage(data){
  return request({
    url: '/order/removePackage',
    data,
    method: 'post',
    handleError: true,
  })
}

/**
 * 获取未处理订单筛选时间设置
 * @returns {Promise<unknown>}
 */
export function getUntreatedOrderScreenTime(params){
  return request({
    url: '/order/getUntreatedOrderScreenTime',
    params
  })
}

/**
 * 获取物流调度设置
 * @returns {Promise | Promise<unknown>}
 */
export function getCutOffSetting(params){
  return request({
    url: '/order/getCutOffSetting',
    params
  })
}

/**
 * 获取物流调度设置
 * @returns {Promise | Promise<unknown>}
 */
export function getAccountCutOffListData(params){
  return request({
    url: '/order/getAccountCutOffListData',
    params
  })
}

/**
 * 生成拣货单tiktok
 * @param data
 * @returns {Promise | Promise<unknown>}
 */
export function batchOrderCreatePickingByTikTok(data){
  return request({
    url: `/order/batchOrderCreatePickingByTikTok`,
    data,
    method: 'post',
    handleError: true,
    timeout: 180000, // 3分钟
  })
}

/**
 * 获取订单运行的物流商
 * @param data
 * @returns {Promise | Promise<unknown>}
 */
export function tiktokGetShippingProviders(data){
  return request({
    url: `/order/tiktokGetShippingProviders`,
    data,
    method: 'post',
    handleError: true,
    timeout: 180000, // 3分钟
  })
}

/**
 * 输入物流单号生成拣货单
 * @param data
 * @returns {Promise | Promise<unknown>}
 */
export function batchOrderCreatePickingByOneself(data){
  return request({
    url: `/order/batchOrderCreatePickingByOneself`,
    data,
    method: 'post',
    handleError: true,
    timeout: 180000, // 3分钟
  })
}

/**
 * custom订单传快递单贴单
 * @param data
 * @returns {Promise | Promise<unknown>}
 */
export function stickerCustomOrder(data){
  return request({
    url: '/order/stickerCustomOrder',
    data,
    method: 'post',
    handleError: true,
  })
}

/**
 * 获取希音图片材料列表
 * @returns {Promise | Promise<unknown>}
 */
export function getSiAccountImageList(params){
  return request({
    url: '/order/getSiAccountImageList',
    params
  })
}

/**
 * 获取希音店铺列表
 * @returns {Promise | Promise<unknown>}
 */
export function getSiAccountDataList(params){
  return request({
    url: '/order/getSiAccountDataList',
    params
  })
}

/**
 * 创建一条希音图片材料记录
 * @param data
 * @returns {Promise | Promise<unknown>}
 */
export function addSiAccountImageData(data){
  return request({
    url: '/order/addSiAccountImageData',
    data,
    method: 'post',
    handleError: true,
  })
}

/**
 * 修改希音材料图片
 * @param data
 * @returns {Promise<unknown>}
 */
export function saveSiAccountImageData(data){
  return request({
    url: `/order/saveSiAccountImageData`,
    method: 'post',
    data,
    handleError: true,
  })
}

/**
 * 删除希音材料图片
 * @param data
 * @returns {Promise<unknown>}
 */
export function delSiAccountImageData(data){
  return request({
    url: `/order/delSiAccountImageData`,
    method: 'post',
    data,
    handleError: true,
  })
}

/**
 * 获取希音图片
 * @param id
 * @returns {Promise | Promise<unknown>}
 */
export function getSiAccountImage(id){
  return request({
    url: `/order/getSiAccountImage/${id}`,
    method: 'get',
  })
}

/**
 * 手动更新履约时间表
 * @returns {Promise | Promise<unknown>}
 */
export function saveCutOff(){
  return request({
    url: `/order/saveCutOff`,
    method: 'get',
  })
}

/**
 * 履约时间表是否更新完成
 * @returns {Promise | Promise<unknown>}
 */
export function cutOffCollectIsDone(){
  return request({
    url: `/order/cutOffCollectIsDone`,
    method: 'get',
  })
}
